package com.qr.order.controller;

import com.qr.order.entity.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    /**
     * 基于Ribbon的形式调用
     *      客户端声明LoadBalance之后
     *      调用将ip和端口，直接替换为我们想要调用的服务名即可完成相应的调用
     */
    @RequestMapping(value = "/buy/{id}",method = RequestMethod.GET)
    public Product findByIdRibbon(@PathVariable Integer id) throws IOException {
        Product forObject = restTemplate.getForObject("http://service-product/product/1", Product.class);
        System.out.println(forObject);
        return forObject;
    }

}
